import Blockly from 'blockly/core'
import 'blockly/python_compressed'
import 'blockly/blockly_compressed'
import 'blockly/blocks_compressed'

Blockly.Blocks.in_function = {
  init: function () {
    this.appendValueInput('key')
      .setCheck('Number', 'String')
      .setAlign(Blockly.ALIGN_CENTRE)
    this.appendDummyInput().appendField(
      new Blockly.FieldDropdown([
        ['in', 'IN'],
        ['not in', 'NOTIN'],
        ['is', 'IS'],
        ['is not', 'ISNOT']
      ]),
      'in_op'
    )
    this.appendValueInput('dict').setCheck('Number', 'String', 'List')
    this.setInputsInline(true)
    this.setOutput(true)
    this.setColour(230)
    this.setTooltip('')
    this.setHelpUrl('')
  }
}

// 代码格式：range(upperRange, lowerRange)
Blockly.Python.in_function = function (block) {
  const inkey = Blockly.Python.valueToCode(
    block,
    'key',
    Blockly.Python.ORDER_NONE
  )
  const dropdownInOp = block.getFieldValue('in_op')
  const indict = Blockly.Python.valueToCode(
    block,
    'dict',
    Blockly.Python.ORDER_NONE
  )
  const code = inkey + ' ' + dropdownInOp + ' ' + indict
  return [code, Blockly.Python.ORDER_NONE]
}

export default Blockly
